<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/11/7
  Time: 13:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/mb/jsp/common.jsp" %>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>提现记录</title>
</head>
<body ontouchstart="">
<div class="detailTop pf w100 of">
    <div class="w100 of tc cf f18">
        <span class="pa" style="left: 2px;" onclick="javascript:history.back();"><img src="mb/images/top_back_white.png"
                                                                                      style="margin-top: 4px;height: 40px;width: 40px;"/></span>
		提现记录
    </div>
</div>
<div id="container" class="container db jz mgt45" style="padding-bottom: 0;">

    <div id="resText"></div><!--resText-->
    <div id="loading" class="w100">
        <img src="mb/images/loading.gif" alt="正在加载" class="db jz hauto" style="width: 15px;">
        <div class="w100 tc f10 c9">正在加载</div>
    </div>
</div>

<script>

    var curpage = 1;
    var total = 1;

    /**
     * 加载新数据
     */
    function getData() {
        $.ajax({
            url: "PlugServlet",
            data: JSON.stringify({m: 216, curpage: curpage}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {
                showProgressDg()
            },
            success: function (data) {
                if (data.state == 1) {
                    // 刷新页面
                    total = data.total;
                    refreshPage(data.list);
                } else {
                    // 其他错误弹出提示
                    showToast(data.info);
                }
            },
            error: function (data) {
                showToast(data.info);
            },
            complete: function () {
                closeProgressDg();
            }
        });
    }

    function getItemHtml(data) {
    console.log(data);
    
    
        var endtime = '';
        
        if (data.finishtime != '' && data.finishtime != null) {
            endtime = dataToString(data.finishtime, "yyyy年MM月dd日   HH:mm:ss");
        }
        
        var finishBlock = "";
        var btnBlock = "";
         var falseBlock = "";
         
         
        /**
	     * 0:待批 1已批　2提现成功 3拒绝 4导出数据 5:失败
	     * @param state
	     */
         switch (data.state) {
            case '0':
                finishBlock = '<p class="orange2 mgl10 f14">正在审批中...</p>';
                btnBlock= '<span class="db br2 tc ffa f15 w100 h100  btnOrangeWith">待审批</span>';
                break;
            case '1':
                finishBlock = '<p class="orange2 mgl10 f14">审批成功，正在为您提现中...</p>';
                btnBlock= '<span class="db br2 tc ffa f15 w100 h100  btnOrangeWith">待提现</span>';
                break;
            case '2':
                finishBlock = '<p class="c3 mgl10 f14">' + endtime + '</p>';
                btnBlock= '<span class="db tc ffa f15 w100 h100 cf btnOrange">待审批</span>';
                break;
            case '3':
                finishBlock = '<p class="cred mgl10 f14">拒绝受理!</p>';
                break;
            case '4':
                finishBlock = '<p class="orange2 mgl10 f14">导出数据</p>';
                break;
            case '5':
                stateStr = '<p class="cred mgl10 f14">提现失败</p>';
                
                falseBlock = '<div class="df w100 withDrawRecord">'
					     		 + '<img src="mb/images/with1.png">'
					     		 + '<span class="db c3 mgl10 f14" for="moneyCash">失败原因：</span>'
					     	 	 + '<p class="c3 mgl10 f14 fw600">' + data.errormsg + '</p>'
					     	 + '</div>';
                break;
            default:
                stateStr = '<p class="orange2 mgl10 f14 fw600">未知错误</p>';
                 btnBlock= '<span class="db br2 tc ffa f15 w100 h100 cf btnGray">待审批</span>';
                falseBlock = "";
                break;
        }
        

        var html = ''
                + '<section class="wdrSection pr w92 jz bcf of mgt10">'
                	 + '<article  class="w92 jz pdb10 b-b">'
                		 + '<div class="df w100 withDrawRecord">'
				     		 + '<img src="mb/images/with1.png">'
				     		 + '<span class="db c3 f14" for="moneyCash">提现金额：</span>'
				     	 	 + '<p class="c3 mgl10 f16 fw600">' + data.rmb + '</p>'
				     	 + '</div>'
				     	  + '<div class="df w100 withDrawRecord">'
				     		 + '<img src="mb/images/with-star.png">'
				     		 + '<span class="db c3 f14" for="moneyCash">提现时间：</span>'
				     	 	 + '<p class="c3 mgl10 f14">' + dataToString(data.time, "yyyy年MM月dd日   HH:mm:ss") + '</p>'
				     	 + '</div>'
				     	  + '<div class="df w100 withDrawRecord">'
				     		 + '<img src="mb/images/with-end.png">'
				     		 + '<span class="db c3 f14" for="moneyCash">提现结束：</span>'
				     	 	 + finishBlock
				     	 + '</div>'
                	 + '</article>'
	                + '<article class="w92 jz of clearfix pdt10 pdb10 wdrSectionBottom">'
	               		+ '<div class="fr tr fb" style="width: 32%;margin:0">'
		               		 + btnBlock
		                + '</div>'
	                + '</article>'
                
                
                + '</section>'
                + '';

        return html;
    }

    /**
     * 刷新列表页面
     * @param data
     */
    function refreshPage(data) {
        var html = '<div id="resText"></div>'
                + '<div id="loading" class="w100">'
                + '<img src="mb/images/loading.gif" alt="正在加载" class="db jz hauto" style="width: 15px;">'
                + '<div class="w100 tc f10 c9">正在加载</div>'
                + '</div>';
        $("#container").html(html);

        if (data == null) {
            showToast("暂无提现记录！");
            return;
        }

        html = '';

        for (var i = 0; i < data.length; i++) {
            html += getItemHtml(data[i])
        }

        $("#resText").before($(html));
    }

    $(function () {
        $(window).bind('scroll', function () {
            show()
        });
    });

    function show() {
        if ($(window).scrollTop() + $(window).height() >= $(document).height()) {
            loadNext();
        }
    }

    /**
     * 加载下一页数据
     */
    function loadNext() {
        if (curpage < total) {
            curpage++;

            $.ajax({
                url: "PlugServlet",
                data: JSON.stringify({m: 216, curpage: curpage}),
                type: 'post',
                dataType: 'json',
                contentType: "application/json;charset=utf-8",
                beforeSend: function () {
                    $("#loading").show();
                },
                success: function (data) {
                    if (data.state == 1) {
                        // 刷新页面
                        total = data.total;
                        // 加载更多
                        if (data.list != null) {
                            var html = '';
                            for (var i = 0; i < data.length; i++) {
                                html += getItemHtml(data[i])
                            }

                            $("#resText").before($(html));
                        }
                    } else {
                        // 其他错误弹出提示
                        showToast(data.info);
                    }
                },
                error: function (data) {
                    showToast(data.info);
                },
                complete: function () {
                    $("#loading").hide();
                }
            });
        }
    }

    /**
     * 0:待批 1已批　2提现成功 3拒绝 4导出数据 5:失败
     * @param state
     */
    function getStateStr(state) {
        var stateStr = '';
        var falseBlock = "";
        switch (state) {
            case '0':
                stateStr = '待批';
                break;
            case '1':
                stateStr = '已批';
                break;
            case '2':
                stateStr = '提现成功';
                break;
            case '3':
                stateStr = '拒绝';
                break;
            case '4':
                stateStr = '导出数据';
                break;
            case '5':
                stateStr = '失败';
                break;
            default:
                stateStr = '未知';
                break;
        }
        return stateStr;
       
    }

    curpage = 1;
    getData();

</script>

</body>
</html>
